package com.java.comprehensive.arithmetic.leecode.easy;

/**
 * @program: comprehensive-service
 *
 * @description: Sqrt(x)
 *
 * @author: 窦绍飞
 *
 * @create: 2021-11-24 14:25
 **/
public class LeetCode_69 {
	/** 求算数平方根  A^2 == B  A是B算数平方根（ 算数平方跟 特指正数）*/
	public static int mySqrt(int x) {
		if (x == 0 || x == 1) {
			return x;
		}
		int mid = 1+(x >> 1);
		int result = 0;
		for (int i = 1; i <= mid; i++) {
			long temp = (long)i * i;
			if(temp>x){
				result = i -1;
				break;
			}else if(temp == x){
				result = i;
				break;
			}
		}
		return result;
	}

	/** 右移一位 除以 2  两位 除以5*/
	public static void main(String[] args) {
		// int num = 3 + ((5 - 3) >> 1);
		int nums = 2147483647;
		System.out.println(mySqrt(nums));
	}
}
